<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工单标题" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入工单管理标题" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="选择类型" prop="workOrderId">
        <el-select v-model="queryParams.workOrderId" placeholder="请选择下拉选择" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in listTWordOrderTypeInfo" :key="index" :label="item.wordOrderName"
            :value="item.id" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="工单状态" prop="audit">
        <el-select v-model="queryParams.audit" placeholder="请选择下拉选择" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in auditList" :key="index" :label="item.label" :value="item.value"
            :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="TUserWorkOrderInfoList">
      <el-table-column type="selection" align="center" />
      <el-table-column label="数据主键" align="center" prop="id" v-if="false" />
      <el-table-column label="用户名称" align="center" prop="userName" />
      <el-table-column label="工单管理标题" align="center" prop="title" />
      <el-table-column label="工单管理类别名称" align="center" prop="wordOrderName" :show-overflow-tooltip="true" />
      <el-table-column label="申请理由" align="center" prop="reason" :show-overflow-tooltip="true" />
      <!-- <el-table-column label="产品名称" align="center" prop="terminalName" /> -->
<!--      <el-table-column label="图片" align="center" prop="terminalImg">
        <template slot-scope="scope">
          <el-popover placement="left" trigger="click" width="400">
            <img :src="scope.row.terminalImg" width="100%" />
            <img slot="reference" :src="scope.row.terminalImg" :alt="scope.row.terminalImg"
              style="max-height: 70px;max-width: 70px; padding:5px" />
          </el-popover>
        </template>
      </el-table-column>-->
      <el-table-column label="工单描述" align="center" prop="workOrderDescribe" :show-overflow-tooltip="true" />
      <el-table-column label="工单描述图片" align="center" prop="describeImg" >
        <template   slot-scope="scope">
          <span v-for="(item,index) in (scope.row.describeImg || '').split(',')" :key="index">
            <el-popover placement="left" trigger="click" width="400">
                <img :src="item" width="100%" />
                <img
                  slot="reference"
                  :src="item"
                  :alt="item"
                  style="max-height: 50px;max-width: 50px;padding:5px;"
                />
            </el-popover>
        </span>
        </template>
      </el-table-column>
      <el-table-column label="工单审核" align="center" prop="auditShow" />
      <el-table-column label="驳回理由" align="center" prop="rejectReason" :show-overflow-tooltip="true" />
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row,scope.index)"
            v-hasPermi="['pos:TUserWorkOrderInfo:query']">详细</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="auditPass(scope.row)"
            v-if="scope.row.auditShow =='待审核'?true:false" v-hasPermi="['pos:TUserWorkOrderInfo:edit']">审核通过</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="auditOpen(scope.row)"
            v-if="scope.row.auditShow =='待审核'?true:false" v-hasPermi="['pos:TUserWorkOrderInfo:edit']">审核驳回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!--工单审核驳回模态框-->
    <el-dialog :visible.sync="open">
      <el-form :model="form">
        <el-form-item label="主键id" prop="id" v-show="false">
          <el-input v-model="form.id" placeholder="主键id" />
        </el-form-item>
        <el-form-item label="驳回原因" prop="rejectReason">
          <el-input v-model="form.rejectReason" type="textarea" placeholder="请输入多行文本"
            :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="auditReject">确 定</el-button>
      </div>
    </el-dialog>


    <!-- 详细 -->
    <el-dialog title="工单详细" :visible.sync="openDetails" width="700px" append-to-body>
      <el-form ref="form" :model="formDetails" label-width="150px" size="mini">
        <el-row>
          <!--          <el-col :span="12">
            <el-form-item label="操作模块：">{{ form.title }} / {{ typeFormat(form) }}</el-form-item>
            <el-form-item
              label="登录信息："
            >{{ form.operName }} / {{ form.operIp }} / {{ form.operLocation }}</el-form-item>
          </el-col>-->
          <!--          <el-col :span="12">
            <el-form-item label="请求地址：">{{ form.operUrl }}</el-form-item>
            <el-form-item label="请求方式：">{{ form.requestMethod }}</el-form-item>
          </el-col>-->
          <el-col :span="24">
            <el-form-item label="工单标题：">{{ formDetails.title }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="工单申请时间：">{{ formDetails.createTime }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="选择类型：">{{ formDetails.wordOrderName }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="申请理由：">{{ formDetails.reason }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="工单描述：">{{ formDetails.workOrderDescribe }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="描述图片：">
              <span v-for="(item,index) in (formDetails.describeImg || '').split(',')" :key="index">
                <el-popover placement="left" trigger="click" width="400">
                  <img :src="item" width="100%" />
                  <img slot="reference" :src="item" :alt="item" style="max-height: 70px;max-width: 70px;padding:5px;" />
                </el-popover>
              </span>
            </el-form-item>
            <el-col :span="24">
              <el-form-item label="工单驳回理由：">{{ formDetails.rejectReason }}</el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDetails = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listTUserWorkOrderInfo,
    getTUserWorkOrderInfo,
    auditPass,
    addTUserWorkOrderInfo,
    updateTUserWorkOrderInfo,
    exportTUserWorkOrderInfo,
    listTWordOrderTypeInfo
  } from "@/api/pos/TUserWorkOrderInfo";

  export default {
    name: "TUserWorkOrderInfo",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 工单管理表格数据
        TUserWorkOrderInfoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        openDetails: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          userName: null,
          title: null,
          workOrderId: null,
          workOrderName: null,
          reason: null,
          terminalName: null,
          terminalImg: null,
          describe: null,
          describeImg: null,
          audit: null,
          rejectReason: null,
          auditTime: null
        },
        // 表单参数
        form: {},
        formDetails: {},
        // 表单校验
        rules: {},

        listTWordOrderTypeInfo: [],
        auditList: [{
          "label": "待审核",
          "value": 0
        }, {
          "label": "审核通过",
          "value": 1
        }, {
          "label": "审核驳回",
          "value": 2
        }],
      };
    },
    created() {
      this.getList();
      listTWordOrderTypeInfo().then(response => {
        console.log(response)
        this.listTWordOrderTypeInfo = response;
      });
    },
    methods: {
      /** 查询工单管理列表 */
      getList() {
        this.loading = true;
        listTUserWorkOrderInfo(this.queryParams).then(response => {
          this.TUserWorkOrderInfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          userId: null,
          userName: null,
          title: null,
          workOrderId: null,
          workOrderName: null,
          reason: null,
          terminalName: null,
          terminalImg: null,
          describe: null,
          describeImg: null,
          audit: null,
          rejectReason: null,
          createTime: null,
          auditTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },

      /** 审核驳回模态框 */
      auditOpen(row) {
        this.reset();
        this.open = true;
        this.form.id = row.id
      },


      // /** 审核驳回 */
      auditReject() {
        var id = this.form.id;
        var rejectReason = this.form.rejectReason;
        var audit = "2";
        const data = {
          id,
          rejectReason,
          audit
        }
        updateTUserWorkOrderInfo(data).then(response => {
          this.$modal.msgSuccess("审核驳回");
          this.open = false;
          this.reset();
          this.getList();
        });
      },
      //审核通过按钮
      auditPass(row) {
        var id = row.id;
        var audit = '1';
        auditPass(id, audit).then(response => {
          this.$modal.msgSuccess("审核通过");
          this.getList();
        });
      },

      /** 详细按钮操作 */
      handleView(row) {
        this.openDetails = true;
        this.formDetails = row;
      },



      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateTUserWorkOrderInfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addTUserWorkOrderInfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      }
    }
  };
</script>
